package twel.probenprophet.profile.spells;

import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.util.Collection;

import javax.inject.Inject;
import javax.inject.Singleton;

import twel.probenprophet.base.utility.Utf8InputStreamReader;
import twel.probenprophet.profile.spells.xdiml2.SpellXmlLoader;
import twel.probenprophet.profile.spells.xdiml2.jaxb.SpellDefinition;

@Singleton
public class SpellRepository {

	private final SpellXmlLoader loader;

	@Inject
	public SpellRepository(SpellXmlLoader spellXmlLoader) {
		this.loader = spellXmlLoader;
	}

	public Collection<SpellDefinition> getSpells(Reader reader) {
		return loader.load(reader);
	}

	public Collection<SpellDefinition> getBundledSpells() {
		InputStream inputStream = getClass().getResourceAsStream("/data/spells.xml");
		InputStreamReader inputStreamReader = new Utf8InputStreamReader(inputStream);
		return getSpells(inputStreamReader);
	}
}
